//
//  XJHomeStatusModel.swift
//  新浪微博
//
//  Created by 徐绩 on 16/4/20.
//  Copyright © 2016年 ayumi. All rights reserved.
//

import UIKit

class XJHomeStatusModel: NSObject {

    var id: Int64 = 0
    //文本
    var text: String?
    //创建时间
    var created_at: String?
    //来源
    var source: String?
    //当前用户信息
    var user: XJUserModel?
    //转发微博
    var retweeted_status: XJHomeStatusModel?
    //配图
    var pic_urls: [XJStatusUserInfo]?
    
    //字典转模型构造函数
    init(dict: [String: AnyObject]) {
        
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    //将user中的字典转成模型
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            guard let dict = value as? [String: AnyObject] else{
                return
            }
            user = XJUserModel(dict: dict)
        }else if key == "retweeted_status" {
        
            guard let dict = value as? [String: AnyObject] else{
                return
            }
            retweeted_status = XJHomeStatusModel(dict: dict)
        }else if key == "pic_urls" {
            
            guard let dicts = value as? [[String: AnyObject]] else{
                return
            }
            var tempArr = [XJStatusUserInfo]()
            for dict in dicts {
            
                let info = XJStatusUserInfo(dict: dict)
                tempArr.append(info)
            }
            pic_urls = tempArr
        
        }else{
        
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
}
